package com.sky.criteria;


import java.util.ArrayList;
import java.util.List;

/**
 * 关键角色,  过滤器接口
 */
interface Filter {
    boolean isLoggable(String word);


}

/**
 * 关键角色 具体过滤器
 * 废话过滤器
 */
class NonsenseFilter implements Filter {

    String shit = "屎";
    String piss = "尿";
    String fart = "屁";

    String[] shieldList = {shit, piss, fart};


    @Override
    public boolean isLoggable(String record) {
        for (String s : shieldList) {
            if (record.contains(s)) {

                return false;
            }
        }
        return true;
    }
}


/**
 * 关键角色 具体过滤器
 * 脏话过滤器
 */
class DirtyTalkFilter implements Filter {

    String fuck = "fuck";
    String ass = "ass";
    String bitch = "bitch";

    String[] shieldList = {fuck, ass, bitch};


    @Override
    public boolean isLoggable(String record) {
        for (String s : shieldList) {
            if (record.contains(s)) {
                return false;
            }
        }
        return true;
    }

}


class Logger {

    /**
     * 关键角色 , 过滤器链
     */
    static List<Filter> filterChain = new ArrayList<>();

    static {

        filterChain.add(new NonsenseFilter());
        filterChain.add(new DirtyTalkFilter());
    }


    void warn(String message) {
        doLog("warn", message);
    }

    void serve(String message) {
        doLog("serve", message);
    }

    private void doLog(String type, String message) {

        for (Filter filter : filterChain) {
            if (!filter.isLoggable(message)) {
                return;
            }
        }
        if (type.equalsIgnoreCase("warn")) {
            System.out.println("WARN " + message);
        } else if (type.equalsIgnoreCase("serve")) {
            System.out.println("ERROR " + message);
        }

    }


}


/**
 * date : 2024-09-13
 * <p>
 * logback  level  ;
 * jul      level  ;
 *
 * @author : wushikai
 */
public class JULApplication {


    public static void main(String[] args) {
        Logger logger = new Logger();
        logger.serve("fuck you  !! ");
        logger.serve("放你妈的屁 !! ");
        logger.serve("吃屎吧你 !! ");
        logger.warn("我在学习 !! ");
        logger.serve("我中弹了 !! ");
    }
}
